package com.dwx.gmall.product.controller;


import com.dwx.gmall.common.result.Result;
import com.dwx.gmall.common.result.ResultCodeEnum;
import com.dwx.gmall.model.product.BaseCategory1;
import com.dwx.gmall.model.product.BaseCategory2;
import com.dwx.gmall.model.product.BaseCategory3;
import com.dwx.gmall.product.service.CategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
@Api(tags = "商品分类")
@RequestMapping("/admin/product")
@RestController
public class CategoryAdminController {

    @Autowired
    CategoryService categoryService;

    @ApiOperation(value = "获取所有一级分类")
    @GetMapping("/getCategory1")
    public Result<List<BaseCategory1>> getCategory1(){
        List<BaseCategory1> baseCategory1s=categoryService.getCategory1();
        return Result.ok(baseCategory1s);
    }

    @ApiOperation(value = "根据一级分类Id获取二级分类")
    @GetMapping("/getCategory2/{category1Id}")
    public Result<List<BaseCategory2>> getCategory2(
            @ApiParam(value = "一级分类ID",required = true)
            @PathVariable("category1Id") Long category1Id
    ){
        if(category1Id>0){
            List<BaseCategory2> baseCategory2s=categoryService.getCategory2(category1Id);
            return Result.ok(baseCategory2s);
        }
        return Result.build(null, ResultCodeEnum.SECKILL_ILLEGAL);
    }

    @ApiOperation(value = "根据二级分类Id获取二级分类")
    @GetMapping("/getCategory3/{category2Id}")
    public Result<List<BaseCategory3>> getCategory3(
            @ApiParam(value = "二级分类ID",required = true)
            @PathVariable("category2Id") Long category2Id
    ){
        if(category2Id>0){
            List<BaseCategory3> baseCategory3s=categoryService.getCategory3(category2Id);
            return Result.ok(baseCategory3s);
        }
        return Result.build(null, ResultCodeEnum.SECKILL_ILLEGAL);

    }


}
